package com.example.wangyeming.getuidemo;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;

import com.example.wangyeming.getuidemo.utils.AppUtil;

/**
 * Created by wangyeming on 15-6-10.
 */
public class TestService extends Service {

    private static final String TAG = "TestService";

    private IBinder binder = new TestService.TestBinder();
    private Handler handler = new Handler();
    private Runnable task = new Runnable() {
        public void run() {
            AppUtil.isRunningForeground(TestService.this);
            handler.postDelayed(this, 3 * 1000);//设置延迟时间，此处是5秒
        }
    };

    @Override
    public IBinder onBind(Intent intent) {
        return binder;
    }

    @Override
    public void onCreate() {
        Log.i(TAG, "onCreate");
        super.onCreate();
        handler.postDelayed(task, 5000);//延迟调用
        handler.post(task);//立即调用
    }

    //定义内容类继承Binder
    public class TestBinder extends Binder {
        //返回本地服务
        TestBinder getService() {
            return TestBinder.this;
        }
    }
}
